import $ from 'jquery'

export default {
    state: {
        isLoading: true,
        goodsList: [
            // {
            // 	id: 1,
            // 	title: 'macbook Retina 13.3" ME662 (2013)',
            // 	thumbnail_url: 'http://media.bizwebmedia.net//sites/72783/data/images/2016/2/4713895macbook_pro_retina.png',
            // 	price: 999.9,
            // 	quantity: 10,
            // 	description: "3.0GHz Dual-core Haswell Intel Core i5 Turbo Boost up to 3.2 GHz, 3MB L3 cache 8GB (two 4GB SO-DIMMs) of 1600MHz DDR3 SDRAM"
            // },{
            // 	id: 2,
            // 	title: '新款背包大容量多层防水牛津布单肩斜挎包尼龙布包旅游休闲男包',
            // 	thumbnail_url: 'https://gw.alicdn.com/bao/uploaded/i3/2207450776976/O1CN017tafgS21P3cnynZag_!!0-item_pic.jpg_220x10000Q75.jpg',
            // 	price: 27.6,
            // 	quantity: 15,
            // 	description: '新款大容量休闲单肩斜挎包'
            // },{
            // 	id: 3,
            // 	title: '海牌海苔64包韩国进口儿童寿司紫菜片包饭拌饭原味芥末味零食海飘',
            // 	thumbnail_url: 'https://g-search3.alicdn.com/img/bao/uploaded/i4/i3/1669874709/O1CN01ybvz7L1keloLIdwvg_!!0-item_pic.jpg_580x580Q90.jpg_.webp',
            // 	price: 19.9,
            // 	quantity: 10,
            // 	description: "下饭帮手 孩子爱吃"
            // },{
            // 	id: 4,
            // 	title: 'Retina MacBook Pro 13 inch MF841',
            // 	thumbnail_url: 'http://media.bizwebmedia.net//sites/72783/data/images/2016/2/4713895macbook_pro_retina.png',
            // 	price: 1000,
            // 	quantity: 0,
            // 	description: "2.9 Ghz Dual-Core Intel Core i5 Broadwell Tubro boost up to 3.3 GHz with L3 3MB cache"
            // },{
            //     id: 5,
            // 	title: '衬衫连衣裙女春秋中长款2022新款长袖洋气时尚法式高级感收腰显瘦',
            // 	thumbnail_url: 'https://gw.alicdn.com/bao/uploaded/i3/1672930604/O1CN01yUi4fw1GKfzgwyUu4_!!0-item_pic.jpg_300x300q90.jpg_.webp',
            // 	price: 228,
            // 	quantity: 125,
            // 	description: "秋装新品 精细做工 优选面料 七天退换"
            // }
        ]
    },
    getters: {
        goodsList: (state) => {
            return state.goodsList;
        },
        isProductLoading: (state) => {
            return state.isLoading;
        }
    },
    mutations: {
        updateGoodsList (state, goodsList) {
            state.goodsList = goodsList;
            state.isLoading = false;
        },
		getGoodsList(state, data) {
			state.goodsList = []
			for (const goods of data) {
				state.goodsList.push(goods)
			}
		}
    },
    actions: {
		sendPage(context, {currentPage, pageSize}) {
			$.ajax({
				url: "http://127.0.0.1:8888/eshop/goods",
				type: "post",
				contentType: 'application/json',
				data: JSON.stringify({
					currentPage: currentPage,
					pageSize: pageSize,
				}),
				success(resp) {
					console.log(resp.data.records)
					context.commit('getGoodsList', resp.data.records)
				},
				error(resp) {
					console.log(currentPage, pageSize)
					console.log('error')
					console.log(resp)
				}
			})
		}
    },
    modules: {
        
    }
}
